package com.rjkj.medicalwaste.viewmodels

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.room.Query
import com.rjkj.medicalwaste.base.BaseViewModel
import com.rjkj.medicalwaste.bean.GarbageBean
import com.rjkj.medicalwaste.bean.HospitalBean
import com.rjkj.medicalwaste.network.response.catchException
import com.rjkj.medicalwaste.network.response.next
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

class SearchHospitalViewModel :BaseViewModel(){
    val queryString = MutableStateFlow(String)
    val hospitalList = MutableLiveData<List<HospitalBean>>()
    fun getQueryHospital(url:String,query: String) {
        viewModelScope.launch {
            request(false) {
                findHospital(url = url,message = query)
            }.next {
                if(code==200){
                    hospitalList.value = this.data
                    tips.value = "查询成功"
                }

            }.catchException {
                printStackTrace()
            }

        }
    }

}